package com.dhj.streamTest2;

import com.dhj.streamTest.entity.Author;

import java.util.List;
import java.util.Optional;

import static com.dhj.streamTest.entity.AuthorList.getAuthors;

public class Demo7 {

    public static void main(String[] args) {
        List<Author> authors = getAuthors();

        Optional<Author> first = authors.stream().distinct().sorted().findFirst();
        first.ifPresent(author -> System.out.println(author.getName()+"--"+author.getAge()));

        System.out.println("----------------------------");

        Optional<Author> first1 = authors.stream().distinct()
                .sorted((o1, o2) -> o2.getAge()-o1.getAge()).findFirst();

        first1.ifPresent(author -> System.out.println(author.getName()+"--"+author.getAge()));

        System.out.println("----------------------------");


        Optional<Author> first2 = authors.stream().distinct()
                .min((o1, o2) -> o2.getAge() - o1.getAge());

        first2.ifPresent(author -> System.out.println(author.getName()+"--"+author.getAge()));

    }
}
